package com.yyge.service.impl;

import com.yyge.entity.Admin;
import com.yyge.mapper.AdminMapper;
import com.yyge.service.AdminService;
import com.yyge.vo.R;
import org.slf4j.Logger;
import org.slf4j.LoggerFactory;

public class AdminServiceImpl implements AdminService {
        private static Logger logger = LoggerFactory.getLogger(AdminServiceImpl.class);
        private AdminMapper adminMapper = null;
   @Override
    public R insert(Admin admin) {
        // 调用数据访问层
        int insert=adminMapper.insert(admin);
        logger.debug("数据访问层执行新增方法完成，数据库返回受影响的行数为：" + insert);
        return insert>0?R.ok("新增成功！"):R.fail("新增失败！");
    }

    @Override
    public R deleteByPrimaryKey(Integer key) {
        int deleteByPrimaryKey=adminMapper.deleteByPrimaryKey(key);
        R r=new R();
        if(deleteByPrimaryKey>0){
            r.setCode(200);
            r.setMessage("删除成功！");
        }else{
            r.setCode(-1);
            r.setMessage("删除失败！");
        }
        return r;
    }

    @Override
    public R updateByPrimaryKey(Admin admin) {
        int undate=adminMapper.updateByPrimaryKey(admin);
        R r=new R();
        if(undate>0){
            r.setCode(200);
            r.setMessage("修改成功！");
        }else{
            r.setCode(-1);
            r.setMessage("修改失败！");
        }
        return r;
    }

    @Override
    public R selectByPrimaryKey(Integer key) {
        Admin addrInfo=adminMapper.selectByPrimaryKey(key);
        R r=new R();
        r.setData(addrInfo);
        return r;
    }
}
